<template>
	<view class="page" v-if="checkPermission(['WORKFLOW:APPROVAL'])">
		<view class="meeting">
			<view class="header">{{title}}</view>
			<view class="attr">
				<view class="list">
					<view class="item" v-if="processType == 'meeting'">
						<view class="key">日期</view>
						<text class="value">{{ date }}</text>
					</view>
					<view class="item">
						<view class="key">申请人</view>
						<view class="value">
							<img :src="photo" alt="" class="photo">
							<text class="cen">{{ name }}</text>
						</view>
					</view>
					<view class="item">
						<view class="key">部门</view>
						<text class="value">{{ dept }}</text>
					</view>
					<view class="item">
						<view class="key">开始时间</view>
						<text class="value">{{ start }} {{startTime}}</text>
					</view>
					<view class="item">
						<view class="key">结束时间</view>
						<text class="value">{{ end }} {{endTime}}</text>
					</view>
					<view class="item" v-if="typeName!=null">
						<view class="key">{{ProcesstypeName}}类型</view>
						<text class="value">{{typeName}}</text>
					</view>
					<view class="item" v-if="typeName=='线下会议'||processType == 'evection'">
						<view class="key">地点</view>
						<view class="value">{{ place }}</view>
					</view>
					<view class="item" v-if="reason!=null">
						<view class="key">{{ProcesstypeName}}原因</view>
						<view class="value">{{ reason }}</view>
					</view>
				</view>
				<view>
					<text class="desc">{{ desc }}</text>
				</view>
			</view>
			<view class="members" v-if="processType == 'meeting'">
				<view class="number">参会者（{{ members.length }}人）</view>
				<view class="member">
					<view class="user" v-for="one in members" :key="one.id">
						<image :src="one.photo" mode="widthFix" class="photo"></image>
						<text class="name">{{ one.name }}</text>
					</view>
				</view>
			</view>
			<block v-if="taskId!=null">
				<button class="btn" @tap="approvalMeeting('同意')" type="primary">同意</button>
				<button class="btn" @tap="approvalMeeting('不同意')" type="warn">不同意</button>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				processType: null,
				ProcesstypeName:'',
				taskId: null,
				id: null,
				uuid: null,
				title: '',
				date: '',
				start: '',
				end: '',
				startTime:'',
				endTime:'',
				typeArray: ['在线会议', '线下会议'],
				typeName:'',
				typeIndex: 0,
				place: '',
				desc: '',
				reason:'',
				members: [],
				name:'',
				dept:'',
				photo:'',
				carName:'',
				carPhoto:''
			}
		},
		onLoad(options) {
			this.processType = options.processType
			this.id = options.id
			if (options.hasOwnProperty('taskId')) {
				this.taskId = options.taskId
			}
		},
		onShow() {
			let that = this
			if (that.processType == 'meeting') {
				that.ProcesstypeName="会议"
				that.ajax(
					that.url.searchMeetingById, 'POST', {
						id: that.id
					},
					function(resp) {
						let result = resp.data.result;
						that.uuid = result.uuid;
						that.title = result.title;
						that.date = result.date;
						that.start = result.start;
						that.end = result.end;
						// that.typeIndex = result.type - 1;
						if(result.type==1){
							that.typeName="在线会议"
						}else{
							that.typeName="线下会议"
						}
						that.place = result.place;
						let desc = result.desc;
						if (desc != null && desc != '') {
							that.desc = desc;
						}
						that.members = result.members;
					}
				);
			} else if(that.processType=="leave"){
				that.ProcesstypeName="请假"
				that.ajax(that.url.selectLeaveById,'POST',{
					id: that.id
				},function(resp) {
					let result = resp.data.result;
					console.log('result',result);
					that.title=result.title;
					that.start=result.start;
					that.end=result.end;
					that.startTime=result.startTime;
					that.endTime=result.endTime;
					if(result.type==1){
						that.typeName="病假"
					}else if(result.type==2){
						that.typeName="事假"
					}else if(result.type==3){
						that.typeName="年假"
					}else{
						that.typeName="其他"
					}
					that.reason=result.reason;
					that.name=result.name;
					that.dept=result.dept_name;
					that.photo=result.photo
				})
			}else if(that.processType=="car"){
				that.ProcesstypeName="用车"
				that.ajax(that.url.selectCarUseById,'POST',{
					id: that.id
				},function(resp) {
					let result = resp.data.result;
					console.log('result',result);
					that.start=result.start;
					that.end=result.end;
					that.startTime=result.startTime;
					that.endTime=result.endTime;
					that.reason=result.reason;
					that.typeName=result.name;
					that.name=result.creater;
					that.dept=result.dept_name;
					that.photo=result.userPhoto
				})
			}else if(that.processType=="evection"){
				that.ProcesstypeName="出差"
				that.ajax(that.url.selectEvectionById,'POST',{
					id: that.id
				},function(resp) {
					let result = resp.data.result;
					console.log('result',result);
					that.start=result.start;
					that.end=result.end;
					that.startTime=result.startTime;
					that.endTime=result.endTime;
					that.reason=result.reason;
					that.typeName=(result.carName==null?"不需要用车":"需要用车")
					that.carName=result.carName
					that.carPhoto=result.carPhoto
					that.name=result.creater;
					that.dept=result.dept_name;
					that.photo=result.uerPhoto;
					that.place=result.place
				})
			}else if(that.processType=="ot"){
				that.ProcesstypeName="加班"
				that.ajax(that.url.selectOtById,'POST',{
					id: that.id
				},function(resp) {
					let result = resp.data.result;
					console.log('result',result);
					that.start=result.start;
					that.end=result.start;
					that.startTime=result.startTime;
					that.endTime=result.endTime;
					that.reason=result.reason;
					that.name=result.name;
					that.dept=result.dept_name;
					that.photo=result.photo;
				})
			}
		},
		methods: {
			approvalMeeting: function(approval) {
				let that = this;
				let a="Reject";
				if(approval=="同意"){
					a="Approved"
				}
				let data={
					instanceId: that.taskId,
					approval: a,
					types:that.processType,
					code:that.code
				}
				uni.showModal({
					title: '提示信息',
					content: '你' + approval + '这条申请？',
					success: function(resp) {
						if (resp.confirm) {
							that.ajax(
								that.url.processApprove, 'POST', data, function(resp) {
									uni.showToast({
										title: '处理完成',
										icon: 'success',
										complete: function() {
											setTimeout(function() {
												uni.navigateBack({});
											}, 2000);
										}
									});
								}
							);
						}
					}
				});
			}

		}
	}
</script>

<style lang="less">
	@import url("approval.less");
</style>
